﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using HiCore.Extensions.DependencyInjection;
using HiCore.WebApi.Example.IRepository;
using HiCore.WebApi.Example.DbContexts;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Builder;
using HiCore.Extensions.UnitOfWork.EntityFramework;
using HiCore.Extensions.EventBus.Kafka;
using HiCore.Extensions.UnitOfWork.EntityFramework.Domain;

namespace HiCore.WebApi.Example.Repository
{
    public static class _ServiceCollectionExtensions
    {
        public static IServiceCollection AddMyDbContextRepository(this IServiceCollection services, IConfiguration configration)
        {
            services.AddDbContext<MyDbContext>(options =>
                options
                    .UseMySql(configration.GetConnectionString("ConnectionString"), new MySqlServerVersion(new Version(8, 0, 27)))
                    .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
                    //.LogTo(Console.WriteLine, LogLevel.Information)
                    //.EnableSensitiveDataLogging()
                    //.EnableDetailedErrors()
            );

            services.AddUnitOfWork<MyDbContext>();

            services.AddScoped<ITestRepository, TestRepository>();

            return services;
        }      
    }
}
